<?php
require_once APP_PATH . '/user/model.php';
function profile_password_action() {
	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
		//提交保存
		profile_password_save_action();
	} else {
		//显示编辑页面
		profile_password_show_action();
	}

}
/**
 * 显示profile页面
 * @param  string
 * @return [type]
 */
function profile_password_show_action() {
	checkLogin();
	include APP_ADMIN_VIEW . 'profile/password.php';
}

function profile_password_save_action() {
	checkLogin();
	$uid = $_SESSION['uid'];
	//新建
	$oldpassword = isset($_POST['oldpassword']) ? trim($_POST['oldpassword']) : '';
	$newpassword = isset($_POST['newpassword']) ? trim($_POST['newpassword']) : '';
	$confirmpassword = isset($_POST['confirmpassword']) ? intval($_POST['confirmpassword']) : 0;

	if ($newpassword != $confirmpassword) {
		header("Location: /" . APP_ADMIN_URI . "/profile/password");
		exit();
	}
	$ret = user_model_update_password_by_id($uid, $oldpassword, $newpassword);
	if ($ret) {
		header("Location: /" . APP_ADMIN_URI . "/profile/info");
	} else {
		echo "modify password failed.";
	}
}